<?php
use yii\helpers\Html;
use common\utils\DomainUtil;

?>
<div id="site_nav">
    <div class="wrap clear">
        <div class="login_bar">
            <p class="site_home" style="display:none;" title="明源云采购"><i class="icon"></i><a
                    href="<?= DomainUtil::getDomainLink("MainPage", "") ?>">云采购首页</a></p>

            <p class="login_info" id="show_login_user" style="display:none;">
                <span class="login_name" id="showTopCompanyName"></span>
                <a class="link_account" id="showTopCompanyUrl" href="#" rel="nofollow">我的桌面</a>
                <span class="line_split">|</span>
                <a class="btn_logout" id="btn_logout" rel="nofollow"
                   href="<?= DomainUtil::getDomainLink("Login", "/view/logout.do") ?>">退出</a>
            </p>

            <p class="login_info" id="show_login_info">
                您可以&nbsp;&nbsp;<a class="link_sigin" href="<?= DomainUtil::getDomainLink("Login", "") ?>"
                                  rel="nofollow">登录</a>
                <span class="line_split">|</span>
                <a class="link_reg" href="<?= DomainUtil::getDomainLink("Register", "") ?>" rel="nofollow">免费注册</a>
            </p>
        </div>
        <div class="nav_link">
            <p class="site_favorite">
                <i class="icon"></i>
                <a href="javascript:void(0)" onclick="bookmark('<?= DomainUtil::getDomainLink("MainPage", "") ?>',
                    '明源云采购')"
                   title="明源云采购" rel="sidebar" rel="nofollow">收藏站点</a>
            </p>
        </div>
    </div>
</div>
<script type="text/javascript">
    function bookmark(url, title) {
        try {
            if (window.sidebar) {
                window.sidebar.addPanel(title, url, "");
            } else if (document.all || !!(navigator.userAgent.match(/Trident/) && navigator.userAgent.match(/rv:11/))) {
                window.external.AddFavorite(url, title);
            } else {
                alert('对不起，您的浏览器不支持加入收藏夹功能，您可以尝试通过快捷键ctrl + d加入到收藏夹。');
            }
        } catch (e) {
            alert("对不起，您的浏览器不支持加入收藏夹功能，您可以尝试通过快捷键'ctrl + d'加入到收藏夹。");
        }
    }

    function getTopInfo(name) {
        var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
        if (arr = top.document.cookie.match(reg)) return unescape(arr[2]);
        else return "";
    }

    function showLoginUserInfo(type, name) {
        if (!type || type == "" || (type != 1 && type != 2) || !name || name == "") {
            return;
        }
        $("#show_login_user").show();
        $("#show_login_info").hide();

        if (type == 1) {
            $("#showTopCompanyUrl").attr("target", '_blank');
            $("#showTopCompanyUrl").attr("href", '<?=DomainUtil::getDomainLink("GysBackstage","")?>');
        } else {
            $("#showTopCompanyUrl").attr("target", '_top');
            $("#showTopCompanyUrl").attr("href", '<?=DomainUtil::getDomainLink("KfsBackstage","")?>');
        }
        $("#showTopCompanyName").text(name);
        $("#showTopCompanyName").attr("title", $("#showTopCompanyName").text());
    }

    (function ($) {
        //load current user info
        showLoginUserInfo(getTopInfo("companyType"), getTopInfo("companyName"));
    })($);
</script>